package org.zsl.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.zsl.model.User;

import java.util.ArrayList;
import java.util.List;


/**
 *   @RestController = @Controller + @Responsebody
 * */
@RestController
@RequestMapping("/json")
@CrossOrigin
public class JsonController {

    @RequestMapping("/json")
    public String json(){

        User user = new User();
        user.setUsername("admin");

        return JSON.toJSONString(user);
    }


    @RequestMapping("/json2")
    public String json2(){

        User user = new User();
        user.setUsername("admin2");

        return JSON.toJSONString(user);
    }


    @RequestMapping("/list")
    public String list(){

        List<User> userList = new ArrayList<>();

        User user1 = new User();
        user1.setUsername("admin1");


        User user2 = new User();
        user2.setUsername("admin2");

        userList.add(user1);
        userList.add(user2);

       return JSON.toJSONString(userList);
    }
}
